/**
 * Created by PengLing on 2017/7/3.
 */
'use strict';

const request = require('superagent');

module.exports = {
    entry: (app, router, opts) => {
        const apiRoot = `${opts.host}${opts.match}`;
        const req = {
            get: (url) => {
                return request.get(`${apiRoot}${url}`);
            },

            post: (url, data) => {
                return request
                    .post(`${apiRoot}${url}`)
                    .set('Content-Type', 'application/json')
                    .send(data);
            },

            put: (url, data) => {
                return request
                    .put(`${apiRoot}${url}`)
                    .set('Content-Type', 'application/json')
                    .send(data);
            },

            delete: (url) => {
                return request.del(`${apiRoot}${url}`);
            }
        };

        app.iota = app.iota || {};
        app.iota.request = req;
    }
};
